#!/bin/bash
#set -x

DOMAIN="atzlinux.com"
#NS="f1g1ns1.dnspod.net"
NS="f1g1ns2.dnspod.net"
SUBDOMAIN="sc-bz-lt-apt"
RECORDID="2065402362"
NSIP=`host $SUBDOMAIN.$DOMAIN $NS|grep address|awk -F address {'print $2'}|sed s/\ //g`

OLDWIP=`cat oldwip.txt`
NOWWIP=`wip`

# https://cloud.tencent.com/document/product/1427/56158
if [ $NOWWIP != $OLDWIP ] || [ $NOWWIP != $NSIP ]
then
source $HOME/venv/bin/activate && tccli dnspod ModifyDynamicDNS --cli-unfold-argument --Domain $DOMAIN --RecordId  $RECORDID --RecordLine '默认' --SubDomain $SUBDOMAIN --Value $NOWWIP --Ttl 600 --detail
echo $NOWWIP > oldwip.txt
fi
